package strategy;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

/**
 * Spring Boot支付策略演示类
 */
@SpringBootApplication
public class SpringPaymentDemo {
    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(SpringPaymentDemo.class, args);
        PaymentContext paymentContext = context.getBean(PaymentContext.class);

        // 使用默认的现金支付（在PaymentContext构造函数中已设置）
        System.out.println("===== 使用默认的现金支付 =====");
        paymentContext.executePayment(100.0);

        // 切换到信用卡支付
        System.out.println("\n===== 切换到信用卡支付 =====");
        paymentContext.setStrategy("creditCardPayment");
        paymentContext.executePayment(200.0);

        // 切换到支付宝支付
        System.out.println("\n===== 切换到支付宝支付 =====");
        paymentContext.setStrategy("alipayPayment");
        paymentContext.executePayment(300.0);

        context.close();
    }
}